import argparse, numpy as np, pandas as pd
from scipy.spatial import cKDTree

def ripley_L(df, max_neighbors=64):
    xyz = np.vstack([df['x'],df['y'],df['z']]).T
    tree = cKDTree(xyz)
    d, _ = tree.query(xyz, k=min(max_neighbors, len(df)))
    # 用第10-50个邻居的平均距离代表局部尺度（简化版）
    r = d[:, 10:50].mean(axis=1).mean()
    # L 值越小说明越接近均匀（这里返回 r 作为近似指标）
    return float(r)

if __name__ == "__main__":
    ap = argparse.ArgumentParser()
    ap.add_argument("--check", type=str, required=True)
    args = ap.parse_args()
    df = pd.read_csv(args.check)
    print("Ripley L (approx):", ripley_L(df))
    
